﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPStore.Host.Start
{
	public class PluginsConfig
	{
		internal static void LoadPlugins(Microsoft.Practices.Unity.IUnityContainer container, string rootFolder)
		{
			Console.WriteLine("try to load plugins");

			var configFile = System.IO.Path.Combine(rootFolder, "plugins.config");
			var pluginLoaderService = new ERPStore.Extensibility.PluginLoaderService();
			var pluginEnumeratorService = new ERPStore.Extensibility.XmlConfigPluginEnumerator(configFile, rootFolder);
			var plugins = pluginEnumeratorService.EnumeratePlugins();

			GlobalConfiguration.Configuration.Logger.Info("Found {0} plugins", plugins.Count());
			pluginLoaderService.Load(plugins);
			Console.WriteLine("plugins loaded");
		}

	}
}
